﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Attack : MonoBehaviour
{
    //一次平A造成的伤害
    public int damage;
    //攻击距离
    public float attackDistance;
    //攻击速度
    public float attackSpeed;
    //攻击目标
    private SummonAnimal attackObject;


    public int Damage
    {
        get
        {
            return damage;
        }

        set
        {
            damage = value;
        }
    }

    public float AttackDistance
    {
        get
        {
            return attackDistance;
        }

        set
        {
            attackDistance = value;
        }
    }

    public float AttackSpeed
    {
        get
        {
            return attackSpeed;
        }

        set
        {
            attackSpeed = value;
        }
    }

    public SummonAnimal AttackObject
    {
        get
        {
            return attackObject;
        }

        set
        {
            attackObject = value;
        }
    }

    //是否到达攻击距离
    public bool InAttackDistance(SummonAnimal selfAnimal)
    {
        //attackObject 为空应在外面处理，此处为了判断安全
        if (attackObject != null)
        {
            Vector2 obj1= new Vector2(selfAnimal.postion.x,selfAnimal.postion.z);

            Vector2 obj2=new Vector2(AttackObject.postion.x,AttackObject.postion.z);
            if (Vector2.Distance(obj1, obj2) < attackDistance)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }

    

    //攻击造成伤害
    public void DoDamage()
    {
        if (attackObject != null)
        {
            attackObject.HP -= damage;
        }
    }
}
